//
//  YeeTabBarController.m
//  YWBaseFrameWork
//
//  Created by 余伟 on 2017/1/12.
//  Copyright © 2017年 NeiQuan. All rights reserved.
//

#import "YeeTabBarController.h"
#import "YeeNavigationController.h"
#import "YeeHomeVC.h"//首页
#import "YeeKindVC.h"//分类
#import "YeeMineVC.h"
#import "YeeShopCarVC.h"
@interface YeeTabBarController ()<UITabBarDelegate,UITabBarControllerDelegate>
{
    

    
}
@end

@implementation YeeTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configureTab];
    [self makeChildrenViewController];
    self.delegate=self;
}
#pragma mark --配置相关字体等
-(void)configureTab
{
    UITabBarItem *item                 = [UITabBarItem appearance];
    //设置默认状态文字的颜色
    NSMutableDictionary *md            = [NSMutableDictionary dictionary];
    
    md[NSForegroundColorAttributeName] = [UIColor  grayColor];
    [item setTitleTextAttributes:md forState:UIControlStateNormal];
    //设置高亮状态文字的颜色
    NSMutableDictionary *higMd            = [NSMutableDictionary dictionary];
    higMd[NSForegroundColorAttributeName] =kNavBarThemeColor;
    [item setTitleTextAttributes:higMd forState:UIControlStateSelected];
    self.tabBar.tintColor = kNavBarThemeColor;
  
}
-(void)makeChildrenViewController
{
    self.tabBar.translucent = YES;
    //设置数据源
    NSArray *vcNames = @[@"YeeHomeVC", @"YeeKindVC",@"UIViewController",  @"YeeShopCarVC",@"YeeMineVC"];
    
    NSArray *imageArray=@[@"icon_shouye_weidianji",@"icon_shoucang_weidianji",@"icon_gouwuche_weidianji",@"icon_gouwuche_weidianji",@"icon_shezhi_weidianji"];
    
    NSArray *selectedimageArray=@[@"icon_shouye_yidianji",@"icon_shoucang_yidianji",@"icon_gouwuche_yidianji",@"icon_gouwuche_yidianji",@"icon_shezhi_yidianji"];
    
    NSArray *titleArray=@[@"首页",@"类别",@"分类 ",@"购物车",@"我的"];
    NSMutableArray *vcArr = [NSMutableArray array];
    NSMutableArray *nvArr = [NSMutableArray array];
    for (NSInteger i = 0; i < vcNames.count; i++)
    {
        Class vcClass = NSClassFromString(vcNames[i]);
        UIViewController *vc = [[vcClass alloc] init];
        vc.title = titleArray[i];
        vc.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageArray[i]] ];
        vc.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@",selectedimageArray[i]]];
        YeeNavigationController *nc = [[YeeNavigationController alloc] initWithRootViewController:vc];
        [vcArr addObject:vc];
        [nvArr addObject:nc];
    }
    self.viewControllers = nvArr;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
   // NSLog(@"%i",self.selectedIndex);
    
    
}
#pragma mark UITabBarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    
   
}
- (void)animationWithIndex:(NSInteger) index
{
    NSMutableArray * tabbarbuttonArray = [NSMutableArray array];
    for (UIView *tabBarButton in self.tabBar.subviews)
    {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabbarbuttonArray addObject:tabBarButton];
        }
    }
    CABasicAnimation*pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulse.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration = 0.08;//持续时间
    pulse.repeatCount= 1;//执行次数
    pulse.autoreverses= YES;
    pulse.fromValue= [NSNumber numberWithFloat:0.8];
    pulse.toValue= [NSNumber numberWithFloat:1.25];
    [[tabbarbuttonArray[index] layer]
     addAnimation:pulse forKey:nil];
    
}
- (void)tabBar:(UITabBar *)tabBar willBeginCustomizingItems:(NSArray<UITabBarItem *> *)items __TVOS_PROHIBITED
{
    
}
- (void)tabBar:(UITabBar *)tabBar didBeginCustomizingItems:(NSArray<UITabBarItem *> *)items __TVOS_PROHIBITED
{
    
    
}
- (void)tabBar:(UITabBar *)tabBar willEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed __TVOS_PROHIBITED
{
    
    
}

- (void)tabBar:(UITabBar *)tabBar didEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed __TVOS_PROHIBITED
{
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
